package day04;

import java.util.Random;
import java.util.Scanner;

public class Guessing {
    public static void main(String[] args) {

        int guess, num;
        Scanner scanner = new Scanner(System.in);

        while (true) {
            int max = 100, min = 1, count = 0;
            num = new Random().nextInt(100) + 1;

            while (true) {
                System.out.println("请输入范围为" + min + "-" + max + "的数字：（输入0退出）");
                guess = scanner.nextInt();
                if (guess == 0) {
                    break;
                } else if (guess > max || guess < min) {
                    System.out.println("输入范围不正确，请重新输入！");
                } else if (guess < num) {
                    min = guess;
                    System.out.print("猜小啦！");
                    count++;
                } else if (guess > num) {
                    max = guess;
                    System.out.print("猜大啦！");
                    count++;
                } else {
                    count++;
                    System.out.println("恭喜你猜对了！中奖数字为：" + num + "，一共猜了" + count + "次！");
                    break;
                }
            }

            if (guess == 0) {
                System.out.println("退出成功！");
                break;
            }

        }
    }
}
